| Total Complexity | 2 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 8 | |||
| 9 | @CommandHandler(CreateIngestionCommand) |
||
| 10 | export class CreateIngestionCommandHandler { |
||
| 11 | constructor( |
||
| 12 | @Inject('ISchoolRepository') |
||
| 13 | private readonly schoolRepository: ISchoolRepository, |
||
| 14 | @Inject('IIngestionRepository') |
||
| 15 | private readonly ingestionRepository: IIngestionRepository, |
||
| 16 | ) {} |
||
| 17 | |||
| 18 | public async execute(command: CreateIngestionCommand): Promise<string> { |
||
| 19 | const { schoolId } = command; |
||
| 20 | const school = await this.schoolRepository.findOneById(schoolId); |
||
| 21 | if (!school) { |
||
| 22 | throw new SchoolNotFoundException(); |
||
| 23 | } |
||
| 24 | |||
| 25 | const ingestion = await this.ingestionRepository.save( |
||
| 26 | new Ingestion( |
||
| 27 | school |
||
| 28 | ) |
||
| 29 | ); |
||
| 30 | |||
| 31 | return ingestion.getId(); |
||
| 32 | } |
||
| 34 |